Skip to content

fix(cuda.core): surface real CUDA error in Device.set_current() - #2461

Open
juenglin wants to merge 1 commit into
NVIDIA:mainfrom
juenglin:set-primary-context-bug
Open

fix(cuda.core): surface real CUDA error in Device.set_current()#2461
juenglin wants to merge 1 commit into
NVIDIA:mainfrom
juenglin:set-primary-context-bug

Conversation

@juenglin

@juenglin juenglin commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

closes #2460

Device.set_current() raised a misleading ValueError ("Cannot set NULL
context as current") when cuDevicePrimaryCtxRetain failed, discarding
the actual driver error code and leaving the thread-local error state
polluted.

Replace with HANDLE_RETURN(get_last_error()) to raise CUDAError with
the real driver status, matching the established pattern used elsewhere.

Manually verified by patching get_primary_context to return a failure;
a regression test is not practical because the failure requires
exclusive compute mode (unavailable on WDDM) or hardware error states
that cannot be simulated from Python.

@copy-pr-bot

copy-pr-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the cuda.core Everything related to the cuda.core module label Jul 30, 2026
@juenglin
juenglin marked this pull request as ready for review July 30, 2026 22:37
@juenglin juenglin added this to the cuda.core 1.2.0 milestone Jul 30, 2026
@juenglin juenglin added the bug Something isn't working label Jul 30, 2026
@juenglin juenglin self-assigned this Jul 30, 2026
@github-actions

Copy link
Copy Markdown

@kkraus14

Copy link
Copy Markdown
Collaborator

@juenglin fix looks good, but is there a reasonable way to test this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working cuda.core Everything related to the cuda.core module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Device.set_current() discards real CUDA error and raises misleading ValueError

2 participants